/**
 * 
 */
package sailing.managers;

import java.awt.Color;
import java.awt.Font;

import javax.swing.BorderFactory;
import javax.swing.UIManager;

import org.jb2011.lnf.beautyeye.BeautyEyeLNFHelper;

import sailing.listener.UI;

/**
 * @author kevin
 * 
 */
public class AppUIManager {

	public static String[] DEFAULT14_FONT = new String[] { "ProgressBar.font", "OptionPane.font",
			"OptionPane.messageFont", "TabbedPane.font", "TitledBorder.font" };

	public static String[] DEFAULT12_FONT = new String[] { "Table.font", "TableHeader.font", "CheckBox.font",
			"Tree.font", "Viewport.font", "RadioButtonMenuItem.font", "ToolBar.font", "ColorChooser.font",
			"ToggleButton.font", "Panel.font", "TextArea.font", "Menu.font", "TableHeader.font", "TextField.font",
			"MenuBar.font", "Button.font", "Label.font", "PasswordField.font", "ScrollPane.font", "MenuItem.font",
			"ToolTip.font", "List.font", "EditorPane.font", "Table.font", "RadioButton.font", "CheckBoxMenuItem.font",
			"TextPane.font", "PopupMenu.font", "ComboBox.font" };

	private static AppUIManager instance;

	private AppUIManager() {
	}

	public static AppUIManager getInstance() {
		if (instance == null) {
			instance = new AppUIManager();
		}
		return instance;
	}

	public void updateUI() {
		this.updateFontSetting();
		this.updateLaF();
		this.updateUiOption();
	}

	private void updateUiOption() {
		UIManager.put("OptionPane.messageAreaBorder", BorderFactory.createEmptyBorder(20, 20, 40, 20));
		UIManager.put("Tree.rendererMargins", BorderFactory.createEmptyBorder(3, 10, 3, 10));
	}

	private void updateLaF() {
		try {
			BeautyEyeLNFHelper.debug = true;
			BeautyEyeLNFHelper.frameBorderStyle = BeautyEyeLNFHelper.FrameBorderStyle.osLookAndFeelDecorated;
			// 设置此开关量为false即表示关闭之，BeautyEye LNF中默认是true
			BeautyEyeLNFHelper.translucencyAtFrameInactive = false;

			BeautyEyeLNFHelper.commonFocusedBorderColor = new Color(70, 163, 255);
			// BeautyEyeLNFHelper.commonBackgroundColor = new Color(255, 255, 255);
			UIManager.put("RootPane.setupButtonVisible", false);
			BeautyEyeLNFHelper.launchBeautyEyeLNF();

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private void updateFontSetting() {
		// 调整默认字体
		for (int i = 0; i < DEFAULT12_FONT.length; i++)
			UIManager.put(DEFAULT12_FONT[i], UI.font12);

		for (int i = 0; i < DEFAULT14_FONT.length; i++)
			UIManager.put(DEFAULT14_FONT[i], UI.font14);
	}

}
